﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using IdleTest.DemoBeTest;
using System.Data;
using IdleTest.MSTest;

namespace IdleTest.DemoToUse
{
    [TestClass]
    public class SqlUtilityTest
    {
        /// <summary>
        ///GetDataColumnValue 的测试
        ///</summary>
        [TestMethod()]
        public void GetDataColumnValueTest1()
        {
            AssertCommon.IsEmpty<object, string>(new object[] { null, DBNull.Value, "" },
                true, (object obj) =>
                {
                    return SqlUtility.GetDataColumnValue(obj);
                });

            AssertCommon.AreEqual<string>("abc", SqlUtility.GetDataColumnValue("abc"));

            AssertCommon.AreEqual<string>("string", SqlUtility.GetDataColumnValue(DataProvider.Instance.DataRow["colString"]));
            AssertCommon.AreEqual<string>("123", SqlUtility.GetDataColumnValue(DataProvider.Instance.DataRow["colInt"]));
        }

        /// <summary>
        ///IsDataSetNullOrEmpty 的测试
        ///</summary>
        [TestMethod()]
        public void IsDataSetNullOrEmptyTest()
        {
            //断言为True
            DataSet nullTable = new DataSet();
            nullTable.Tables.Add(new DataTable());
            AssertCommon.IsBoolean<DataSet>(new DataSet[] { null, new DataSet(), nullTable },
                true, (DataSet dsTemp) =>
                {
                    return SqlUtility.IsDataSetNullOrEmpty(dsTemp);
                });

            //断言为false
            DataSet hasNullTable = new DataSet();
            hasNullTable.Tables.Add(new DataTable());
            hasNullTable.Tables.Add(DataProvider.Instance.Table);
            AssertCommon.IsBoolean<DataSet>(new DataSet[] { hasNullTable, DataProvider.Instance.DataSet },
                false, (DataSet dsTemp) =>
                {
                    return SqlUtility.IsDataSetNullOrEmpty(dsTemp);
                });
        }

        /// <summary>
        ///IsDataTableNullOrEmpty 的测试
        ///</summary>
        [TestMethod()]
        public void IsDataTableNullOrEmptyTest()
        {
            //断言为True
            DataTable emptyTable = new DataTable();
            emptyTable.Columns.Add("col");
            AssertCommon.IsBoolean<DataTable>(new DataTable[] { null, new DataTable(), emptyTable }, true,
                (DataTable dtTemp) => { return SqlUtility.IsDataTableNullOrEmpty(dtTemp); });

            //断言为false
            Assert.IsFalse(SqlUtility.IsDataTableNullOrEmpty(DataProvider.Instance.Table));
        }
    }
}
